﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;

namespace Christmas_Card
{
    class Scenario : Panel
    {
        private Image backGround;

        public Form parentForm;

        public Size frame;

        private Timeline timeLine;
        public ArrayList drawingObj;

        private Timer clock;

        public Scenario(Form _parent)
        {
            this.parentForm = _parent;
            this.Parent = this.parentForm;

            drawingObj = new ArrayList();


            this.backGround = new Bitmap(global::Christmas_Card.Properties.Resources.BackGround);
            //this.BackgroundImage = backGround;
            this.parentForm.Size = this.backGround.Size;
            this.Size = this.backGround.Size;
            frame = this.Parent.Size;
            this.Paint += new PaintEventHandler(Scenario_Paint);

            timeLine = new Timeline();
            timeLine.addEvent(new Snow(frame, 1, this));
            timeLine.addEvent(new GreetingText(1, new Point(-600, 300), new Point(300, 500), this));
            timeLine.addEvent(new Bell(this, 1));

            clock = new Timer();
            clock.Interval = 10;
            clock.Tick += new EventHandler(clock_Tick);

            
        }

        void Scenario_Paint(object sender, PaintEventArgs e)
        {
            //throw new NotImplementedException();
            //base.Refresh();

            Image img = new Bitmap(this.Width, this.Height);

            Graphics igr = Graphics.FromImage(img);
            //gr.DrawImage(backGround, 0, 0);
            igr.DrawImage(backGround, 0, 0);
            foreach (PictureBox pb in drawingObj)
                igr.DrawImage(pb.Image, pb.Location.X, pb.Location.Y, pb.Size.Width, pb.Size.Height);

            Graphics gr = e.Graphics;
            gr.DrawImage(img, 0, 0);
            img.Dispose();
            
        }

        void paintScreen()
        {
            Image img = new Bitmap(this.Width, this.Height);

            Graphics igr = Graphics.FromImage(img);
            //gr.DrawImage(backGround, 0, 0);
            igr.DrawImage(backGround, 0, 0);
            foreach (PictureBox pb in drawingObj)
                igr.DrawImage(pb.Image, pb.Location.X, pb.Location.Y, pb.Size.Width, pb.Size.Height);

            Graphics gr = this.CreateGraphics();
            gr.DrawImage(img, 0, 0);
            img.Dispose();
        }

        void clock_Tick(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            this.paintScreen();
        }

        public void start()
        {
            timeLine.perform();
            clock.Start();
        }
    }
}
